package equals;

/**
 * author : yeswater
 * date : 2023/7/10
 */

public class EqualsTest {

    public static void main(String[] args) {
        test1();
    }

    public static void test1() {

        /* 说明 == 对于基本类型 只判断值 */
        int i1 = 128;
        int i2 = 128;
        System.out.println(i1 == i2);
        System.out.println("i1  @" + Integer.toHexString(System.identityHashCode(i1)));
        System.out.println("i2  @" + Integer.toHexString(System.identityHashCode(i2)));

        /* 说明 == 对于引用类型 判断对象的内存地址 */
        Student s1 = new Student();
        Student s2 = new Student();
        System.out.println(s1 == s2);
        System.out.println("s1  @" + Integer.toHexString(System.identityHashCode(s1)));
        System.out.println("s2  @" + Integer.toHexString(System.identityHashCode(s2)));

        Object obj1 = new Student();
        Object obj2 = new Student();
        System.out.println(obj1.equals(obj2));
        System.out.println(obj1.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj1)));
        System.out.println(obj2.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj2)));

        Object obj7 = new String();
        Object obj8 = new String();
        System.out.println(obj7.equals(obj8));
        System.out.println(obj7.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj7)));
        System.out.println(obj8.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj8)));
    }


}

class Student {
    private String name ;

    public Student(String name) {
        this.name = name;
    }

    public Student() {
        this.name = "Lucas";
    }
}
